from django.db import models

# Create your models here.
class User(models.Model):
    name = models.CharField(max_length=32)
    pwd = models.CharField(max_length=32)
    roles = models.ManyToManyField(to="Role")

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "用户表"


class Role(models.Model):
    title = models.CharField(max_length=32)
    permissions = models.ManyToManyField(to="Permission")

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "角色表"


class Menu(models.Model):
    """
    一级菜单表
    """
    title = models.CharField(max_length=32, verbose_name="菜单")
    icon = models.CharField(max_length=32, default='', blank=None)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "菜单列表"


class Permission(models.Model):
    """
    二级菜单表
    """
    title = models.CharField(max_length=32)
    url = models.CharField(max_length=32)
    menu = models.ForeignKey(to="Menu", on_delete=models.CASCADE, null=True,blank=True)

    class Meta:
        verbose_name = "权限表"

    def __str__(self):
        return self.title

__all__ = [Role, User, Permission, Menu]